package com.lanou.service;

import com.lanou.bean.AdminInfo;
import com.lanou.bean.RoleInfo;
import com.lanou.mapper.AdminInfoMapper;
import com.lanou.mapper.RoleInfoMapper;
import com.lanou.mapper.RoleModuleMapper;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by lanouhn on 17/10/18.
 */
@Service("role_module")
public class RoleServiceImpl implements RoleService {

   @Autowired
   private RoleInfoMapper roleInfoMapper;

   @Autowired
   private RoleModuleMapper roleModuleMapper;

    @Override
    public List<RoleInfo> selectAll() {
        return roleInfoMapper.selectAll();
    }



//    删除表数据
    @Override
    public void deleteRoleAndModuleById(Integer roleId) {
      roleInfoMapper.delectRoleModule(roleId);
    }

    @Override
    public int deleteAdminRoel(Integer roleId) {
        return roleInfoMapper.deleteAdminRole(roleId);
    }

    @Override
    public int deleteByPrimaryKey(Integer roleId) {
        return roleInfoMapper.deleteByPrimaryKey(roleId);
    }




    @Override
    public RoleInfo selectByName(String role_name) {
        return roleInfoMapper.selectByName(role_name);
    }



    @Override
    public int insertRoleAndModuleByName(String name) {
        return roleInfoMapper.insertRoleAndModuleByName(name);
    }

    @Override
    public Integer selectIdByName(String name) {
        return roleInfoMapper.selectIdByName(name);
    }

    @Override
    public int selectIdToModule(String moduleName) {
        return roleInfoMapper.selectIdToModule(moduleName);
    }


//    插入关联关系
    @Override
    public int insertRoleModuleById(Integer role_id,Integer module_id) {
        System.out.println(role_id+module_id);
        return roleInfoMapper.insertRoleModuleById(role_id,module_id);
    }


    @Override
    public int updateRoelInfoById(Integer role_id, String name) {
        return roleInfoMapper.updateRoelInfoById(role_id,name);
    }

    @Override
    public RoleInfo selectByRoleId(Integer role_id) {
        return roleInfoMapper.selectByRoelId(role_id);
    }

    @Override
    public List<String> selectAllName() {
        return roleInfoMapper.selectAllName();
    }


    @Override
    public int delectRoleModule(Integer role_id) {
        return roleInfoMapper.delectRoleModule(role_id);
    }
}
